home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 728 < prev    next >
Internet Message Format  |  1996-08-06  |  2KB

  1. Path: tbj.dec.com!diamond
  2. From: diamond@tbj.dec.com (Norman Diamond)
  3. Newsgroups: comp.std.c
  4. Subject: Re: va_list, function calls.
  5. Date: 12 Apr 1996 03:54:08 GMT
  6. Organization: Digital Equipment Corporation Japan , Tokyo
  7. Message-ID: <4kkk50$h94@usenet.pa.dec.com>
  8. References: <4kdk5v$mn@solutions.solon.com>
  9. Reply-To: diamond@tbj.dec.com (Norman Diamond)
  10. NNTP-Posting-Host: jit533.tbj.dec.com
  11.  
  12. In article <4kdk5v$mn@solutions.solon.com>, seebs@solutions.solon.com (Peter Seebach) writes:
  13. >    void foo(int bar, ...) {
  14. >        va_list ap;
  15. >        int i;
  16. >        va_start(ap, bar);
  17. >        for (i = 0; i < bar; ++i)
  18. >            baz(&ap);
  19. >        va_end(ap);
  20. >    }
  21. >    void baz(va_list *ap) { printf("%d\n", va_arg(*ap)); }
  22. >is this legal?  If not, is there a compelling reason?
  23.  
  24. ANSI Classic section 4.8, page 123 lines 12 to 15:  "The object ap may be
  25. passed as an argument to another function; if that function invokes the
  26. va_arg macro with parameter ap, the value of ap in the calling function
  27. is indeterminate and shall be passed to the va_end macro prior to any
  28. further reference to ap."
  29.  
  30. The standard does not quite say that &ap may be passed, but let's try to
  31. pretend that this was an editorial oversight and a TC will permit it.
  32.  
  33. After the first invocation of baz() returns, the value of ap in the
  34. calling function is indeterminate.  ap can be passed to va_end, and I
  35. think that &ap can probably be computed and passed around, but the value
  36. of ap is just as indeterminate in the second invocation of baz() as it
  37. was in main() between the two invocations.
  38.  
  39. What you really want is a TC to say that if &ap is passed then the value
  40. of ap does not become indeterminate.  Ask your national representative to
  41. propose this.
  42. --
  43.  <<  If this were the company's opinion, I would not be allowed to post it.  >>
  44. "I paid money for this car, I pay taxes for vehicle registration and a driver's
  45. license, so I can drive in any lane I want, and no innocent victim gets to call
  46. the cops just 'cause the lane's not goin' the same direction as me" - J Spammer
  47.